// cookie 使用步骤
/**
 *   ###  cookie 使用步骤
 * 1 安装 cookie-parser中间件  npm i cookie-parser
 * 2. 导入 cookie-parser
 * 3. 设置中间件
 */

const express = require('express');

// 2. 导入cookie-parser
const cookieParser = require('cookie-parser');

const app = express();
// 3. 设置中间件
app.use(cookieParser());

// function cookieParser(n){
//     return function(n){
//         console.log(n+123);
//     }
// }

app.get('/',(request, response)=>{
    response.send('home 首页');
})

// 设置cookie
app.get('/set-cookie', (request, response)=>{
    //设置
    response.cookie('username','atguigu');// set-cookie:username=atguigu
    response.cookie('email','123@qq.com',{maxAge:60*3000});
    response.send('登录成功');
})

// 获取cookie
app.get('/get-cookie',(request, response)=>{
    // request.cookies
    console.log(request.cookies);
    response.send('获取成功');
})
// 清楚 cookie
app.get('/clear-cookie' , (request, response)=>{
    response.clearCookie('username');// 通过设置过期时间，实现清除 username cookie
    response.send('清楚cookie')
})

app.listen(80,()=>{
    console.log('server run at 80!');
})